package com.siyoumi.app.modules.sms.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siyoumi.app.entity.SysSmsSend;
import com.siyoumi.app.modules.sms.entity.EnumSmsSendStatus;
import com.siyoumi.app.modules.sms.service.SvcSms;
import com.siyoumi.app.service.SysSmsSendService;
import com.siyoumi.component.XBean;
import com.siyoumi.component.XEnumBase;
import com.siyoumi.component.http.InputData;
import com.siyoumi.controller.AdminApiController;
import com.siyoumi.mybatispuls.JoinWrapperPlus;
import com.siyoumi.util.XReturn;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/xadmin/sms/sms__send__list")
public class sms__send__list
        extends AdminApiController {
    @GetMapping()
    public XReturn index() {
        setPageTitle("短信发送列表");

        InputData inputData = InputData.fromRequest();

        JoinWrapperPlus<SysSmsSend> query = SvcSms.getBean().listSendQuery(inputData);

        IPage<SysSmsSend> page = new Page<>(inputData.getPageIndex(), inputData.getPageSize());
        //list
        IPage<Map<String, Object>> pageData = SysSmsSendService.getBean().getMaps(page, query);
        List<Map<String, Object>> list = pageData.getRecords();
        long count = pageData.getTotal();

        EnumSmsSendStatus enumSmsSendStatus = XEnumBase.of(EnumSmsSendStatus.class);//发送状态
        for (Map<String, Object> item : list) {
            SysSmsSend entity = XBean.fromMap(item, SysSmsSend.class);

            item.put("id", entity.getKey());
            item.put("status", enumSmsSendStatus.get(entity.getSsend_status()));
        }

        getR().setData("list", list);
        getR().setData("count", count);

        return getR();
    }
}
